package com.qfedu.tantu.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qfedu.tantu.dto.DetailDto;
import com.qfedu.tantu.dto.EvalutionCommentAddDto;
import com.qfedu.tantu.dto.EvalutionCommentDto;
import com.qfedu.tantu.entity.Evalution;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface EvalutionDao extends BaseMapper<Evalution> {
    @Select("SELECT e.aid,e.evaluate,e.stars,u.name,u.label,u.headportrait FROM t_evalution e INNER JOIN t_user u ON u.id=e.uid INNER JOIN t_advertisement a ON a.id= e.aid WHERE e.aid=#{aid}")
    List<DetailDto> selectDetail( Integer aid);
    @Select("SELECT e.evaluate,e.ctime,u.name,u.headportrait from t_evalution e inner join t_user u on u.id = e.uid where aid=#{aid} order by ctime desc")
    List<EvalutionCommentDto> selectByAid(Integer aid);
    @Select("SELECT DATEDIFF(ctime,NOW()) FROM t_evalution  where aid=#{aid} order by ctime desc")
    List<Integer> timechange(Integer aid);
//    @Insert("INSERT INTO t_evalution(aid,uid,evaluate,ctime) values(#{aid},#{uid},#{evaluate},#{now()})")
////    int insertComment(@Param("aid") Integer aid,@Param("uid") Integer uid,@Param("evaluate") String evaluate,@Param("ctime") Date ctime);
//    int insertComment(EvalutionCommentAddDto dto);
    @Select("SELECT AVG(stars) FROM t_evalution WHERE aid=#{aid}")
    Double selectStarsDouble(Integer aid);
    @Select("SELECT e.evaluate,e.ctime,u.name,u.headportrait from t_evalution e inner join t_user u on u.id = e.uid ")
    List<EvalutionCommentDto> selectAll();
//    @Select("select ")
    @Select("SELECT DATEDIFF(ctime,NOW()) FROM t_evalution")
    List<Integer> timechange();

}
